home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_13_04
/
allison
/
retref.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-06
|
454b
|
30 lines
LISTING 8 - Returns an object from a function by reference
//retref.cpp: Returning a reference
#include <stdio.h>
int & current(); // Returns a reference
int a[4] = {0,1,2,3};
int index = 0;
main()
{
current() = 10;
index = 3;
current() = 20;
for (int i = 0; i < 4; ++i)
printf("%d ",a[i]);
putchar('\n');
return 0;
}
int & current()
{
return a[index];
}
// Output:
10 1 2 20